package test;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.sql.DataSource;

import org.apache.commons.collections.map.HashedMap;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ui.Model;

import com.cn.bukeManage.controller.ShoppingmallController;
import com.cn.bukeManage.dao.ShoppingmallDao;
import com.cn.bukeManage.dao.UserDao;
import com.cn.bukeManage.pojo.Composition;
import com.cn.bukeManage.pojo.Location;
import com.cn.bukeManage.pojo.Picture;
import com.cn.bukeManage.pojo.Sample;
import com.cn.bukeManage.pojo.Sample_style;
import com.cn.bukeManage.pojo.Style;
import com.cn.bukeManage.pojo.Supplier;
import com.cn.bukeManage.pojo.page.Page;
import com.cn.bukeManage.pojo.page.SamplePage;
import com.cn.bukeManage.service.ShoppingmallService;

public class test {
	ClassPathXmlApplicationContext ctx;

	@Before
	public void init() {
		ctx = new ClassPathXmlApplicationContext("spring-mybatis.xml", "spring-mvc.xml");

	}

	

	@Test
	public void test1() {
		ShoppingmallDao s = ctx.getBean("shoppingmallDao", ShoppingmallDao.class);
		
	}
	@Test
	public void test4() {
		UserDao s = ctx.getBean("UserDao", UserDao.class);
		Map<String,Object>map=new HashMap<String,Object>();
		map.put("page",1);
		map.put("pageSize",10);
		List<Map<String, Object>> map1 = s.selectAllUsers(map);
		for(Map<String, Object> m:map1){
			System.out.println(m.get("username"));
		}
		
		
	}

	@Test
	public void test2() {
		ShoppingmallDao s = ctx.getBean("shoppingmallDao", ShoppingmallDao.class);
		s.deleteCompositionByType(2015, 3);	
	}
	@Test
	public static BufferedImage getBufferedImage(String imgUrl) {
		BufferedImage img=null;
		try {
			URL url=new URL(imgUrl);
			InputStream in = url.openStream();
			 img = ImageIO.read(in);  
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}catch(IOException e){
				e.printStackTrace();
			}
		return img;
	}
	
	@Test
	public  void getBufferedImage1(String imgUrl) {
		BufferedImage s = test.getBufferedImage("http://okwc9gyzs.bkt.clouddn.com/710031-3_20170823_005.jpg");
		System.out.println(s.getWidth()+":"+s.getHeight());
	}
	
		
}
